package com.youlai.boot.factory.controller;

import com.youlai.boot.factory.service.CuttingBedDetailsService;
import jakarta.annotation.security.PermitAll;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.factory.model.form.CuttingBedDetailsForm;
import com.youlai.boot.factory.model.query.CuttingBedDetailsQuery;
import com.youlai.boot.factory.model.vo.CuttingBedDetailsVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

import java.awt.image.BufferedImage;
import java.util.List;

/**
 * 裁床明细前端控制层
 *
 * @author youlaitech
 * @since 2025-08-24 15:02
 */
@Tag(name = "裁床明细接口")
@RestController
@RequestMapping("/api/v1/cutting-bed-details")
@RequiredArgsConstructor
public class CuttingBedDetailsController  {

    private final CuttingBedDetailsService cuttingBedDetailsService;

    @Operation(summary = "裁床明细分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('factory:cutting-bed-details:query')")
    public PageResult<CuttingBedDetailsVO> getCuttingBedDetailsPage(CuttingBedDetailsQuery queryParams) {
        IPage<CuttingBedDetailsVO> result = cuttingBedDetailsService.getCuttingBedDetailsPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增裁床明细")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('factory:cutting-bed-details:add')")
    public Result<Void> saveCuttingBedDetails(@RequestBody @Valid CuttingBedDetailsForm formData ) {
        boolean result = cuttingBedDetailsService.saveCuttingBedDetails(formData);
        return Result.judge(result);
    }

    @Operation(summary = "批量新增裁床明细")
    @PostMapping("/batch")
    @PreAuthorize("@ss.hasPerm('factory:cutting-bed-details:add')")
    public Result<Void> saveBatchCuttingBedDetails(@RequestBody @Valid List<CuttingBedDetailsForm> formDataList) {
        boolean result = cuttingBedDetailsService.saveBatchCuttingBedDetails(formDataList);
        return Result.judge(result);
    }

    @Operation(summary = "获取裁床明细表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('factory:cutting-bed-details:edit')")
    public Result<CuttingBedDetailsForm> getCuttingBedDetailsForm(
        @Parameter(description = "裁床明细ID") @PathVariable Long id
    ) {
        CuttingBedDetailsForm formData = cuttingBedDetailsService.getCuttingBedDetailsFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改裁床明细")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('factory:cutting-bed-details:edit')")
    public Result<Void> updateCuttingBedDetails(
            @Parameter(description = "裁床明细ID") @PathVariable Long id,
            @RequestBody @Validated CuttingBedDetailsForm formData
    ) {
        boolean result = cuttingBedDetailsService.updateCuttingBedDetails(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除裁床明细")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('factory:cutting-bed-details:delete')")
    public Result<Void> deleteCuttingBedDetailss(
        @Parameter(description = "裁床明细ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = cuttingBedDetailsService.deleteCuttingBedDetailss(ids);
        return Result.judge(result);
    }
}
